package com.mlc.core.serviceImpl;

import com.mlc.core.service.SongsService;
import com.mlc.data.dao.SongsDao;
import com.mlc.data.entity.Songs;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @author FireWang
 * @date 2022/03/14 02:46:45
 */
@Service
@AllArgsConstructor
@Transactional
public class SongsServiceImpl implements SongsService {
    private SongsDao songsDao;

    @Override
    public List<Songs> getAll() {
        return songsDao.findAll();
    }

    @Override
    public Songs getById(Integer id) {
        Optional<Songs> songs = songsDao.findById(id);
        return songs.get();
    }

    @Override
    public void insert(Songs songs) {
        songsDao.save(songs);
    }

    @Override
    public void update(Songs songs) {
        songsDao.save(songs);
    }

    @Override
    public void deleteById(Integer id) {
        songsDao.deleteById(id);
    }
}